home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / SETBOX < prev    next >
Encoding:
Text File  |  1986-01-20  |  4.5 KB  |  175 lines

  1. ;-------------------------setbox routine begins--------------------------+
  2. ; NAME  SETBOX
  3. ;
  4. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  5. ;         page :  137
  6. ;
  7. ; ROUTINE FOR FILLING A RECTANGULAR BOX WITH COLOR
  8. ;
  9. ; FUNCTION: This routine fills a rectangular box in the color graphics
  10. ; screen with a given color.
  11. ;
  12. ; INPUT: Upon entry:
  13. ;
  14. ;    x-coordinate of upper left corner is in x1
  15. ;    y-coordinate of upper left corner is in y1
  16. ;    x-coordinate of lower right corner is in x2
  17. ;    y-coordinate of lower right corner is in y2
  18. ;    color of the rectangle is in bits 0 and 1 of color
  19. ;
  20. ; OUTPUT: Just to the screen.
  21. ;
  22. ; REGISTERS USED:  No registers are modified.
  23. ;
  24. ; SEGMENTS REFERENCED:  Upon entry ES must point to the video RAM at
  25. ; 0B8000h and DS must point to the following lookup table for color
  26. ; masks:
  27. ;
  28. ; xtable    dw    0FFC0h, 0FFF0h, 0FFFCh, 0FFFFh
  29. ;        dw    03FC0h, 03FF0h, 03FFCh, 03FFFh
  30. ;        dw    00FC0h, 00FF0h, 00FFCh, 00FFFh
  31. ;        dw    003C0h, 003F0h, 003FCh, 003FFh
  32. ;
  33. ; ROUTINES CALLED:  None
  34. ;
  35. ; SPECIAL NOTES: No bounds checking is performed. The coordinates must
  36. ; be in range and in order.  That is, the following case must be true:
  37. ;
  38. ;    0 <= x1 <= x2 <= 319
  39. ;    0 <= xy <= y2 <= 119    
  40. ;
  41. ; ROUTINE TO FILL A RECTANGULAR BOX
  42. ;
  43. setbox    proc    far
  44. ;
  45.     push    si        ; save registers
  46.     push    di
  47.     push    dx
  48.     push    bx
  49.     push    cx
  50.     push    ax
  51. ;
  52. ; determine byte position for start
  53. ;
  54. ; get y contribution
  55.     mov    ax,y1        ; get starting y-coordinate
  56.     mov    ah,al        ; replicate for odd-even bank
  57.     and    ax,1FEh        ; just one bit gets moved
  58.     sal    ax,1        ; times 4
  59.     sal    ax,1        ; times 8
  60.     sal    ax,1        ; times 16
  61.     mov    di,ax        ; address gets 16 * y-coord
  62.     and    di,7FFh        ; not the odd-even bit
  63.     sal    ax,1        ; times 32
  64.     sal    ax,1        ; times 64
  65.     add    di,ax        ; address gets 80 * y-coord
  66. ;
  67. ; add in x contribution
  68.     mov    ax,x1        ; get x coord
  69.     sar    ax,1        ; divide
  70.     sar    ax,1        ; by 4
  71.     add    di,ax        ; beginning offset
  72. ;
  73. ; count for outer loop
  74.     mov    cx,y2        ; ending y-coord
  75.     sub    cx,y1        ; minus starting y coord
  76.     inc    cx        ; plus 1
  77. ;
  78. ; count for inner loop
  79.     mov    si,x2        ; ending x-coord
  80.     sar    si,1        ; divide
  81.     sar    si,1        ; by 4
  82.     mov    ax,x1        ; starting x-coord
  83.     sar    ax,1        ; divide
  84.     sar    ax,1        ; by 4
  85.     sub    si,ax        ; take the difference
  86. ;
  87. ; get the color
  88.     mov    bx,color    ; get the color
  89.     and    bx,3        ; just between 0 and 3
  90.     mov    dl,cbytes[bx]    ; look up color pattern
  91. ;
  92. ; determine mask for starting and ending bytes
  93.     mov    bx,x1        ; starting byte
  94.     and    bx,3        ; just the pixel posn
  95.     sal    bx,1        ; times 2
  96.     sal    bx,1        ; times 4
  97.     mov    ax,x2        ; ending byte
  98.     and    ax,3        ; just the pixel posn
  99.     add    bx,ax        ; 4 * starting-ending
  100.     sal    bx,1        ; 8 * starting + 2 * ending
  101.     mov    bx,xtable[bx]    ; look up the masks
  102. ;
  103. ; set up masked color bytes
  104.     mov    dh,dl        ; color for the left bytes
  105.     mov    ah,dl        ; color for the middle bytes
  106.     and    dx,bx        ; mask left and right color bytes
  107. ;
  108.     cld            ; forward
  109. ;
  110. sboxloop:
  111.     push    cx        ; save count of outer loop
  112.     push    di        ; save initial byte posn
  113. ;
  114.     mov    cx,si        ; count for inner loop
  115. ;
  116. ; check for only one byte
  117.     mov    al,bh        ; get the mask
  118.     jcxz    sboxloop2    ; if ending byte coincides
  119. ;
  120. ; color leftmost byte of the scan line
  121.     not    al        ; reverse the mask for clearing
  122.     and    al,es: [di]    ; get byte from memory and clear pixels
  123.     or    al,dh        ; put color in place
  124. ; *** possibly changing this to xor will be useful ***
  125.     stosb            ; put the byte in place
  126. ;
  127. ; check for just two bytes
  128.     dec    cx        ; count the byte
  129.     jcxz    sboxloop1    ; done ?
  130. ;
  131. ; color middle byte of scan line
  132.     mov    al,ah        ; color for middle byte
  133.     rep    stosb        ; put middle bytes in place
  134. ;
  135. ; handle rightmost byte of scan line
  136. ;
  137. ; come here if two or more bytes
  138. sboxloop1:
  139.     mov    al,0FFh        ; set the full mask
  140. ;
  141. ; in all cases come here to adjust the masks
  142. sboxloop2:
  143.     and    al,bl        ; bring in right part of the mask
  144.     and    dl,al        ; clear left part of color if needed
  145. ;
  146. ; color the byte
  147.     not    al        ; reverse the mask for clearing
  148.     and    al,es: [di]    ; get byte from memory and clear pixels
  149.     or    al,dl        ; put pixels in the byte
  150. ; *** change to xor would be interesting ***
  151.     stosb            ; put byte back into video RAM
  152. ;
  153. ; compute next scan line
  154.     pop    di        ; restore address of left side of box
  155.     test    di,2000h    ; odd or even line ?
  156.     jz    sboxloop3    ; skip if even
  157.     add    di,80        ; add 80 bytes per line
  158. ;
  159. sboxloop3:
  160.     xor    di,2000h    ; changes banks in any case
  161.     pop    cx        ; restore count for outer loop
  162.     loop    sboxloop    ; next scan line
  163. ;
  164.     pop    ax        ; restore registers
  165.     pop    cx
  166.     pop    bx
  167.     pop    dx
  168.     pop    di
  169.     pop    si
  170. ;
  171.     ret            ; return
  172. ;
  173. setbox    endp
  174. ;-------------------------setbox routine ends---------------------------+
  175.